ref_clone 0.1.0

An implementation of borrows as higher kinded types that can be used to prevent code duplication.
Documentation

This crate provides an implementation of a borrow as a higher kinded type.

This can be used to abstract over the type of borrow by passing the type of the borrow as a type argument.

Example:

#[RefAccessors]
struct Example {
pub value: u8,
}
fn get_example_value<'a, T: RefType>(x: Ref<'a, Example, T>) -> Ref<'a, u8, T> {
let x = x.to_wrapped();
x.value
}
fn main() {
let mut ex = Example {
value: 8
};
{
let ex_ref = Immutable::new(&ex);
println!("{}", get_example_value(ex_ref)); // = 8
}
{
let ex_mut = Mutable::new(&mut ex);
*get_example_value(ex_mut).as_mut() = 1;
}
println!("{}", ex.value); // = 1
{
let ex_ref = Immutable::new(&ex);
println!("{}", get_example_value(ex_ref)); // = 1
}
}